<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>行业资讯 - Ubike自行车行业动态及外贸知识 | 专业博客</title>
    <meta name="description" content="Ubike行业资讯博客，分享自行车行业动态、外贸知识、产品使用技巧等专业内容，助力外贸业务发展。">
    <meta name="keywords" content="自行车行业,外贸知识,行业动态,产品技巧,运动器材博客">
    <meta name="robots" content="index, follow">
    <link rel="canonical" href="https://ubike.com/blog">
    
    <!-- Open Graph Meta Tags -->
    <meta property="og:title" content="Ubike行业资讯 - 自行车行业动态及外贸知识">
    <meta property="og:description" content="专业自行车行业博客，分享行业动态和外贸知识">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://ubike.com/blog">
    <meta property="og:image" content="/static/tp/Logo.png">
    
    <!-- Schema.org Markup -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "Blog",
        "name": "Ubike行业资讯",
        "description": "自行车行业动态及外贸知识博客",
        "url": "https://ubike.com/blog",
        "publisher": {
            "@type": "Organization",
            "name": "Ubike",
            "logo": "https://ubike.com/static/tp/Logo.png"
        }
    }
    </script>
    
    <link rel="stylesheet" href="/static/css/style.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        /* 博客页面专用样式 */
        .blog-container {
            min-height: 100vh;
            background: #f8f9fa;
        }

        .blog-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 30px 20px;
            display: grid;
            grid-template-columns: 1fr 350px;
            gap: 30px;
        }

        /* 博客主内容区 */
        .blog-main {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        }

        /* 侧边栏 */
        .blog-sidebar {
            display: flex;
            flex-direction: column;
            gap: 25px;
        }

        /* 分类筛选 */
        .category-filter {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        }

        .category-filter h3 {
            margin: 0 0 20px 0;
            color: #333;
            font-size: 1.3rem;
            font-weight: 600;
            border-bottom: 2px solid #1e88e5;
            padding-bottom: 10px;
        }

        .category-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .category-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 15px;
            background: #f8f9fa;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            color: #333;
        }

        .category-item:hover {
            background: #e3f2fd;
            transform: translateX(5px);
        }

        .category-item.active {
            background: #1e88e5;
            color: white;
        }

        .category-count {
            background: rgba(255,255,255,0.2);
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 0.8rem;
        }

        /* 博客列表 */
        .blog-list {
            display: flex;
            flex-direction: column;
            gap: 25px;
        }

        .blog-item {
            background: white;
            border-radius: 12px;
            padding: 25px;
            box-shadow: 0 3px 15px rgba(0,0,0,0.08);
            transition: all 0.3s ease;
            cursor: pointer;
            border-left: 4px solid #1e88e5;
        }

        .blog-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 25px rgba(0,0,0,0.15);
        }

        .blog-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 15px;
        }

        .blog-title {
            font-size: 1.4rem;
            font-weight: 600;
            color: #333;
            margin: 0;
            line-height: 1.4;
        }

        .blog-meta {
            display: flex;
            align-items: center;
            gap: 15px;
            margin-bottom: 15px;
            font-size: 0.9rem;
            color: #666;
        }

        .blog-category {
            background: #e3f2fd;
            color: #1e88e5;
            padding: 4px 12px;
            border-radius: 15px;
            font-size: 0.8rem;
            font-weight: 500;
        }

        .blog-summary {
            color: #555;
            line-height: 1.6;
            margin-bottom: 15px;
        }

        .blog-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-top: 1px solid #eee;
            padding-top: 15px;
        }

        .blog-stats {
            display: flex;
            gap: 20px;
            font-size: 0.9rem;
            color: #666;
        }

        .blog-stat {
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .blog-actions {
            display: flex;
            gap: 10px;
        }

        .blog-action {
            background: #f8f9fa;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 0.8rem;
            color: #666;
        }

        .blog-action:hover {
            background: #e3f2fd;
            color: #1e88e5;
        }

        .blog-action.liked {
            background: #ffebee;
            color: #e53935;
        }

        .blog-action.favorited {
            background: #fff3e0;
            color: #f57c00;
        }

        /* 排行榜 */
        .ranking-section {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        }

        .ranking-section h3 {
            margin: 0 0 20px 0;
            color: #333;
            font-size: 1.3rem;
            font-weight: 600;
            border-bottom: 2px solid #1e88e5;
            padding-bottom: 10px;
        }

        .ranking-tabs {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }

        .ranking-tab {
            flex: 1;
            padding: 8px 12px;
            background: #f8f9fa;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9rem;
            text-align: center;
            transition: all 0.3s ease;
        }

        .ranking-tab.active {
            background: #1e88e5;
            color: white;
        }

        .ranking-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .ranking-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .ranking-item:hover {
            background: #e3f2fd;
        }

        .ranking-number {
            width: 24px;
            height: 24px;
            background: #1e88e5;
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.8rem;
            font-weight: bold;
        }

        .ranking-number.top-3 {
            background: #f57c00;
        }

        .ranking-content {
            flex: 1;
        }

        .ranking-title {
            font-size: 0.9rem;
            font-weight: 500;
            margin: 0 0 4px 0;
            line-height: 1.3;
        }

        .ranking-stats {
            font-size: 0.8rem;
            color: #666;
        }

        /* 订阅功能 */
        .subscription-section {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        }

        .subscription-section h3 {
            margin: 0 0 15px 0;
            color: #333;
            font-size: 1.3rem;
            font-weight: 600;
        }

        .subscription-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-bottom: 20px;
        }

        .subscription-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 15px;
            background: #f8f9fa;
            border-radius: 8px;
        }

        .subscribe-btn {
            width: 100%;
            padding: 10px;
            background: #1e88e5;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .subscribe-btn:hover {
            background: #1565c0;
        }

        .subscribe-btn.subscribed {
            background: #4caf50;
        }

        /* 搜索和筛选 */
        .blog-filters {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
            margin-bottom: 25px;
        }

        .search-box {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }

        .search-input {
            flex: 1;
            padding: 12px 15px;
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            font-size: 14px;
        }

        .search-btn {
            padding: 12px 20px;
            background: #1e88e5;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
        }

        .filter-tabs {
            display: flex;
            gap: 10px;
        }

        .filter-tab {
            padding: 8px 16px;
            background: #f8f9fa;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9rem;
            transition: all 0.3s ease;
        }

        .filter-tab.active {
            background: #1e88e5;
            color: white;
        }

        /* 分页 */
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            margin-top: 40px;
        }

        .page-link {
            padding: 8px 16px;
            background: #f8f9fa;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            text-decoration: none;
            color: #333;
            transition: all 0.3s ease;
        }

        .page-link:hover {
            background: #e3f2fd;
        }

        .page-link.active {
            background: #1e88e5;
            color: white;
        }

        /* 移动端适配 */
        @media (max-width: 1024px) {
            .blog-content {
                grid-template-columns: 1fr;
            }
            
            .blog-sidebar {
                order: -1;
            }
        }

        @media (max-width: 768px) {
            .blog-content {
                padding: 20px 15px;
            }
            
            .blog-main {
                padding: 20px;
            }
            
            .blog-header {
                flex-direction: column;
                gap: 10px;
            }
            
            .blog-footer {
                flex-direction: column;
                gap: 15px;
                align-items: flex-start;
            }
            
            .ranking-tabs {
                flex-direction: column;
            }
            
            .filter-tabs {
                flex-wrap: wrap;
            }
        }
    </style>
</head>
<body>
    <!-- 头部区域 -->
    <header class="header">
        <div class="wrap">
            <!-- 导航菜单 -->
            <nav class="main-nav">
                <div class="nav-container">
                    <div class="logo">
                        <a href="/">
                            <img src="/static/tp/Logo.png" alt="ubike">
                        </a>
                    </div>

                    <ul class="nav-menu">
                        <li><a href="/">首页</a></li>
                        <li><a href="/about">关于我们</a></li>
                        <li>
                            <a href="#" onclick="alert('特色服务页面正在开发中...')">特色服务 <i class="fas fa-chevron-down"></i></a>
                            <ul class="dropdown">
                                <li><a href="#" onclick="alert('产品定制页面正在开发中...')">产品定制</a></li>
                                <li><a href="#" onclick="alert('物流配送页面正在开发中...')">物流配送</a></li>
                            </ul>
                        </li>
                        <li>
                            <a href="/products">产品图集</a>
                        </li>
                        <li class="active">
                            <a href="/blog">行业资讯</a>
                        </li>
                        <li>
                            <a href="/contact">联系我们</a>
                        </li>
                    </ul>
                    <div class="nav-right">
                        <!-- 语言切换器 -->
                        <user-language-switcher></user-language-switcher>
                        
                        <div class="search-box">
                            <input type="text" placeholder="搜索...">
                            <button><i class="fas fa-search"></i></button>
                        </div>
                        <div class="contact-info">
                            <span class="email"><i class="fas fa-envelope"></i>h3444850160@gmail.com</span>
                        </div>
                    </div>
                </div>
            </nav>
        </div>
    </header>

    <!-- 页面标题 -->
    <section class="page-title">
        <div class="wrap">
            <h1>行业资讯</h1>
            <p>探索自行车行业最新动态、技术发展和市场趋势</p>
        </div>
    </section>

    <!-- 博客内容区域 -->
    <div class="blog-container">
        <div class="blog-content">
            <!-- 主内容区 -->
            <div class="blog-main">
                <!-- 搜索和筛选 -->
                <div class="blog-filters">
                    <div class="search-box">
                        <input type="text" class="search-input" placeholder="搜索博客文章...">
                        <button class="search-btn"><i class="fas fa-search"></i></button>
                    </div>
                    <div class="filter-tabs">
                        <button class="filter-tab active" data-filter="all">全部</button>
                        <button class="filter-tab" data-filter="latest">最新</button>
                        <button class="filter-tab" data-filter="hot">最热</button>
                        <button class="filter-tab" data-filter="featured">精选</button>
                    </div>
                </div>

                <!-- 博客列表 -->
                <div class="blog-list" id="blogList">
                    <!-- 博客文章将通过JavaScript动态加载 -->
                </div>

                <!-- 分页 -->
                <div class="pagination">
                    <a href="#" class="page-link"><i class="fas fa-chevron-left"></i></a>
                    <a href="#" class="page-link active">1</a>
                    <a href="#" class="page-link">2</a>
                    <a href="#" class="page-link">3</a>
                    <a href="#" class="page-link">4</a>
                    <a href="#" class="page-link"><i class="fas fa-chevron-right"></i></a>
                </div>
            </div>

            <!-- 侧边栏 -->
            <div class="blog-sidebar">
                <!-- 分类筛选 -->
                <div class="category-filter">
                    <h3>博客分类</h3>
                    <div class="category-list">
                        <a href="#" class="category-item active" data-category="all">
                            <span>全部文章</span>
                            <span class="category-count">128</span>
                        </a>
                        <a href="#" class="category-item" data-category="technology">
                            <span>技术发展</span>
                            <span class="category-count">45</span>
                        </a>
                        <a href="#" class="category-item" data-category="market">
                            <span>市场趋势</span>
                            <span class="category-count">32</span>
                        </a>
                        <a href="#" class="category-item" data-category="maintenance">
                            <span>保养维修</span>
                            <span class="category-count">28</span>
                        </a>
                        <a href="#" class="category-item" data-category="review">
                            <span>产品评测</span>
                            <span class="category-count">15</span>
                        </a>
                        <a href="#" class="category-item" data-category="news">
                            <span>行业新闻</span>
                            <span class="category-count">8</span>
                        </a>
                    </div>
                </div>

                <!-- 排行榜 -->
                <div class="ranking-section">
                    <h3>热门排行</h3>
                    <div class="ranking-tabs">
                        <button class="ranking-tab active" data-type="views">阅读量</button>
                        <button class="ranking-tab" data-type="likes">点赞数</button>
                    </div>
                    <div class="ranking-list" id="rankingList">
                        <!-- 排行榜内容将通过JavaScript动态加载 -->
                    </div>
                </div>

                <!-- 订阅功能 -->
                <div class="subscription-section">
                    <h3>订阅最新资讯</h3>
                    <p style="margin-bottom: 15px; color: #666; font-size: 14px;">订阅我们的最新行业资讯，第一时间获取行业动态</p>
                    <div class="subscription-list">
                        <div class="subscription-item">
                            <span>技术发展</span>
                            <button class="subscribe-btn" onclick="subscribeToBlog('technology')" data-category="technology">订阅</button>
                        </div>
                        <div class="subscription-item">
                            <span>市场趋势</span>
                            <button class="subscribe-btn subscribed" onclick="subscribeToBlog('market')" data-category="market">已订阅</button>
                        </div>
                        <div class="subscription-item">
                            <span>保养维修</span>
                            <button class="subscribe-btn" onclick="subscribeToBlog('maintenance')" data-category="maintenance">订阅</button>
                        </div>
                    </div>
                    <div style="margin-top: 20px; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <p style="margin: 0 0 10px 0; font-size: 14px; color: #333;">想要更多定制化服务？</p>
                        <button class="subscribe-btn" onclick="window.location.href='/contact'" style="width: 100%; background: #1e88e5; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; font-weight: 500;">
                            <i class="fas fa-envelope"></i> 联系我们获取定制服务
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 博客订阅功能
        function subscribeToBlog(category) {
            // 跳转到联系我们页面，并传递订阅信息
            const categoryNames = {
                'technology': '技术发展',
                'market': '市场趋势', 
                'maintenance': '保养维修'
            };
            
            const message = `我想订阅关于${categoryNames[category]}的博客内容`;
            
            // 使用URL参数传递订阅信息
            const params = new URLSearchParams({
                subscription: 'blog',
                category: category,
                message: message
            });
            
            window.location.href = `/contact?${params.toString()}`;
        }

        // 页面加载时检查URL参数，自动填充订阅信息
        document.addEventListener('DOMContentLoaded', function() {
            const urlParams = new URLSearchParams(window.location.search);
            const subscription = urlParams.get('subscription');
            
            if (subscription === 'blog') {
                const category = urlParams.get('category');
                const message = urlParams.get('message');
                
                // 这里可以添加自动填充逻辑，如果需要的话
                console.log('博客订阅参数:', { category, message });
            }
        });

        // 处理博客页面内的订阅按钮点击
        document.querySelectorAll('.subscribe-btn').forEach(btn => {
            btn.addEventListener('click', function() {
                const category = this.getAttribute('data-category');
                if (category && !this.classList.contains('subscribed')) {
                    subscribeToBlog(category);
                }
            });
        });
    </script>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="wrap">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>关于我们</h3>
                    <p>【ubike】从"优质生活触手可及"的初心出发，成为专注于自行车、宠物用品行业的电商独立站。</p>
                    <div class="social-links">
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <a href="#"><i class="fab fa-weibo"></i></a>
                        <a href="#"><i class="fab fa-instagram"></i></a>
                    </div>
                </div>
                <div class="footer-section">
                    <h3>营业时间</h3>
                    <p>7x24小时营业</p>
                </div>
                <div class="footer-section">
                    <h3>联系我们</h3>
                    <p>邮箱: h3444850160@gmail.com</p>
                    <p>地址: 河北邢台</p>
                </div>
            </div>
            <div class="footer-bottom">
                <p>© 2025 ubike. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="/static/js/script.js"></script>
    <script>
        // 博客数据管理
        class BlogManager {
            constructor() {
                this.currentFilter = 'all';
                this.currentCategory = 'all';
                this.currentPage = 1;
                this.blogData = [];
                this.categories = [];
                this.popularArticles = [];
            }

            // 初始化博客页面
            async init() {
                try {
                    // 并行加载所有数据
                    await Promise.all([
                        this.loadBlogData(),
                        this.loadCategories(),
                        this.loadPopularArticles()
                    ]);
                    
                    this.renderBlogList();
                    this.renderCategories();
                    this.renderPopularArticles();
                    this.bindEvents();
                } catch (error) {
                    console.error('博客页面初始化失败:', error);
                    this.showFallbackData();
                }
            }

            // 加载博客数据
            async loadBlogData() {
                try {
                    const response = await fetch('/api/blog/posts?page=' + this.currentPage);
                    const result = await response.json();
                    
                    if (result.success) {
                        this.blogData = result.data;
                    } else {
                        throw new Error('API返回失败');
                    }
                } catch (error) {
                    console.warn('从API加载博客数据失败，使用模拟数据:', error);
                    this.blogData = this.getFallbackBlogData();
                }
            }

            // 加载分类数据
            async loadCategories() {
                try {
                    const response = await fetch('/api/blog/categories');
                    const result = await response.json();
                    
                    if (result.success) {
                        this.categories = result.data;
                    } else {
                        throw new Error('API返回失败');
                    }
                } catch (error) {
                    console.warn('从API加载分类失败，使用模拟数据:', error);
                    this.categories = this.getFallbackCategories();
                }
            }

            // 加载热门文章
            async loadPopularArticles() {
                try {
                    const response = await fetch('/api/blog/posts/popular?limit=5');
                    const result = await response.json();
                    
                    if (result.success) {
                        this.popularArticles = result.data;
                    } else {
                        throw new Error('API返回失败');
                    }
                } catch (error) {
                    console.warn('从API加载热门文章失败，使用模拟数据:', error);
                    this.popularArticles = this.getFallbackPopularArticles();
                }
            }

            // 获取模拟博客数据
            getFallbackBlogData() {
                return [
                    {
                        id: 1,
                        title: "2025年自行车行业发展趋势分析",
                        category: "market",
                        content: "随着环保意识的提升和健康生活方式的流行，自行车行业在2025年将迎来新的发展机遇...",
                        author: "张明",
                        created_at: "2025-11-08",
                        views: 2450,
                        likes: 156,
                        comments: 42,
                        featured: true
                    },
                    {
                        id: 2,
                        title: "电动自行车电池技术的最新突破",
                        category: "technology",
                        content: "新型固态电池技术的应用将大幅提升电动自行车的续航能力和安全性...",
                        author: "李华",
                        created_at: "2025-11-07",
                        views: 1890,
                        likes: 98,
                        comments: 28,
                        featured: false
                    },
                    {
                        id: 3,
                        title: "山地自行车保养维护全攻略",
                        category: "maintenance",
                        content: "从链条清洁到刹车调整，全面解析山地自行车的日常保养技巧...",
                        author: "王强",
                        created_at: "2025-11-06",
                        views: 3120,
                        likes: 210,
                        comments: 65,
                        featured: true
                    },
                    {
                        id: 4,
                        title: "城市通勤自行车选购指南",
                        category: "review",
                        content: "针对不同通勤需求，为您推荐最适合的城市自行车型号...",
                        author: "赵敏",
                        created_at: "2025-11-05",
                        views: 1560,
                        likes: 87,
                        comments: 31,
                        featured: false
                    },
                    {
                        id: 5,
                        title: "自行车智能配件市场前景分析",
                        category: "technology",
                        content: "从智能锁到GPS追踪器，智能配件正在改变骑行体验...",
                        author: "陈伟",
                        created_at: "2025-11-04",
                        views: 980,
                        likes: 45,
                        comments: 18,
                        featured: false
                    }
                ];
            }

            // 获取模拟分类数据
            getFallbackCategories() {
                return [
                    { id: 1, name: '技术发展', slug: 'technology', count: 45 },
                    { id: 2, name: '市场趋势', slug: 'market', count: 32 },
                    { id: 3, name: '保养维修', slug: 'maintenance', count: 28 },
                    { id: 4, name: '产品评测', slug: 'review', count: 15 },
                    { id: 5, name: '行业新闻', slug: 'news', count: 8 }
                ];
            }

            // 获取模拟热门文章
            getFallbackPopularArticles() {
                return [
                    {
                        id: 1,
                        title: "2025年自行车行业发展趋势分析",
                        views: 2450,
                        likes: 156
                    },
                    {
                        id: 3,
                        title: "山地自行车保养维护全攻略",
                        views: 3120,
                        likes: 210
                    },
                    {
                        id: 2,
                        title: "电动自行车电池技术的最新突破",
                        views: 1890,
                        likes: 98
                    }
                ];
            }

            // 显示fallback数据
            showFallbackData() {
                this.blogData = this.getFallbackBlogData();
                this.categories = this.getFallbackCategories();
                this.popularArticles = this.getFallbackPopularArticles();
                
                this.renderBlogList();
                this.renderCategories();
                this.renderPopularArticles();
                this.bindEvents();
            }

            // 渲染博客列表
            renderBlogList() {
                const blogList = $('#blogList');
                blogList.empty();
                
                let filteredBlogs = this.blogData;
                
                // 应用分类筛选
                if (this.currentCategory !== 'all') {
                    filteredBlogs = filteredBlogs.filter(blog => blog.category === this.currentCategory);
                }
                
                // 应用排序
                switch(this.currentFilter) {
                    case 'latest':
                        filteredBlogs.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
                        break;
                    case 'hot':
                        filteredBlogs.sort((a, b) => b.views - a.views);
                        break;
                    case 'featured':
                        filteredBlogs = filteredBlogs.filter(blog => blog.featured);
                        break;
                }
                
                // 渲染博客列表
                if (filteredBlogs.length === 0) {
                    blogList.html('<div class="no-results">没有找到相关文章</div>');
                } else {
                    filteredBlogs.forEach(blog => {
                        const blogItem = this.createBlogItem(blog);
                        blogList.append(blogItem);
                    });
                }
            }

            // 创建博客项
            createBlogItem(blog) {
                const categoryNames = {
                    'technology': '技术发展',
                    'market': '市场趋势',
                    'maintenance': '保养维修',
                    'review': '产品评测',
                    'news': '行业新闻'
                };
                
                const categoryName = categoryNames[blog.category] || blog.category;
                const summary = blog.content ? blog.content.substring(0, 100) + '...' : '暂无内容';
                
                return `
                    <div class="blog-item" data-id="${blog.id}">
                        <div class="blog-header">
                            <h3 class="blog-title">${this.escapeHtml(blog.title)}</h3>
                            <span class="blog-category">${categoryName}</span>
                        </div>
                        <div class="blog-meta">
                            <span><i class="fas fa-user"></i> ${blog.author}</span>
                            <span><i class="fas fa-calendar"></i> ${blog.created_at}</span>
                            <span><i class="fas fa-eye"></i> ${blog.views}</span>
                        </div>
                        <p class="blog-summary">${summary}</p>
                        <div class="blog-footer">
                            <div class="blog-stats">
                                <span class="blog-stat">
                                    <i class="fas fa-heart"></i> ${blog.likes}
                                </span>
                                <span class="blog-stat">
                                    <i class="fas fa-comment"></i> ${blog.comments}
                                </span>
                            </div>
                            <div class="blog-actions">
                                <button class="blog-action like-btn" data-id="${blog.id}">
                                    <i class="fas fa-heart"></i> 点赞
                                </button>
                                <button class="blog-action favorite-btn" data-id="${blog.id}">
                                    <i class="fas fa-star"></i> 收藏
                                </button>
                                <button class="blog-action" onclick="viewBlogDetail(${blog.id})">
                                    阅读全文
                                </button>
                            </div>
                        </div>
                    </div>
                `;
            }

            // 渲染分类列表
            renderCategories() {
                const categoryList = $('.category-list');
                
                // 清空现有分类（保留"全部文章"）
                categoryList.find('.category-item:not([data-category="all"])').remove();
                
                // 添加分类项
                this.categories.forEach(category => {
                    const categoryItem = `
                        <a href="#" class="category-item" data-category="${category.slug}">
                            <span>${category.name}</span>
                            <span class="category-count">${category.count}</span>
                        </a>
                    `;
                    categoryList.append(categoryItem);
                });
            }

            // 渲染热门文章
            renderPopularArticles() {
                const rankingList = $('#rankingList');
                rankingList.empty();
                
                this.popularArticles.forEach((article, index) => {
                    const rankingItem = this.createRankingItem(article, index + 1);
                    rankingList.append(rankingItem);
                });
            }

            // 创建排行榜项
            createRankingItem(article, rank) {
                return `
                    <div class="ranking-item" onclick="viewBlogDetail(${article.id})">
                        <div class="ranking-number ${rank <= 3 ? 'top-3' : ''}">${rank}</div>
                        <div class="ranking-content">
                            <div class="ranking-title">${article.title}</div>
                            <div class="ranking-stats">
                                <i class="fas fa-eye"></i> ${article.views} | 
                                <i class="fas fa-heart"></i> ${article.likes}
                            </div>
                        </div>
                    </div>
                `;
            }

            // 绑定事件
            bindEvents() {
                // 分类筛选
                $('.category-item').on('click', (e) => {
                    e.preventDefault();
                    $('.category-item').removeClass('active');
                    $(e.target).closest('.category-item').addClass('active');
                    
                    this.currentCategory = $(e.target).closest('.category-item').data('category');
                    this.renderBlogList();
                });
                
                // 筛选标签
                $('.filter-tab').on('click', (e) => {
                    $('.filter-tab').removeClass('active');
                    $(e.target).addClass('active');
                    
                    this.currentFilter = $(e.target).data('filter');
                    this.renderBlogList();
                });
                
                // 排行榜标签
                $('.ranking-tab').on('click', (e) => {
                    $('.ranking-tab').removeClass('active');
                    $(e.target).addClass('active');
                    
                    const type = $(e.target).data('type');
                    this.loadPopularArticlesByType(type);
                });
                
                // 点赞功能
                $(document).on('click', '.like-btn', (e) => {
                    this.handleLike(e);
                });
                
                // 收藏功能
                $(document).on('click', '.favorite-btn', (e) => {
                    this.handleFavorite(e);
                });
                
                // 搜索功能
                $('.search-btn').on('click', () => {
                    this.handleSearch();
                });
                
                $('.search-input').on('keypress', (e) => {
                    if (e.which === 13) {
                        this.handleSearch();
                    }
                });
            }

            // 处理点赞
            async handleLike(e) {
                const userEmail = localStorage.getItem('userEmail');
                
                if (!userEmail) {
                    alert('请先登录后再点赞');
                    return;
                }
                
                const blogId = $(e.target).closest('.like-btn').data('id');
                const blog = this.blogData.find(b => b.id === blogId);
                
                if (blog) {
                    try {
                        // 调用API更新点赞数
                        await this.updateArticleLikes(blogId, blog.likes + 1);
                        blog.likes++;
                        
                        $(e.target).closest('.like-btn').addClass('liked');
                        $(e.target).closest('.like-btn').html('<i class="fas fa-heart"></i> 已点赞');
                        
                        // 更新显示
                        const likeCount = $(e.target).closest('.blog-item').find('.blog-stat .fa-heart').parent();
                        likeCount.text(` ${blog.likes}`);
                    } catch (error) {
                        console.error('点赞失败:', error);
                        // 本地更新作为fallback
                        blog.likes++;
                        $(e.target).closest('.like-btn').addClass('liked');
                        $(e.target).closest('.like-btn').html('<i class="fas fa-heart"></i> 已点赞');
                    }
                }
            }

            // 处理收藏
            handleFavorite(e) {
                const userEmail = localStorage.getItem('userEmail');
                
                if (!userEmail) {
                    alert('请先登录后再收藏');
                    return;
                }
                
                const blogId = $(e.target).closest('.favorite-btn').data('id');
                
                $(e.target).closest('.favorite-btn').toggleClass('favorited');
                if ($(e.target).closest('.favorite-btn').hasClass('favorited')) {
                    $(e.target).closest('.favorite-btn').html('<i class="fas fa-star"></i> 已收藏');
                    this.saveToFavorites(blogId);
                } else {
                    $(e.target).closest('.favorite-btn').html('<i class="fas fa-star"></i> 收藏');
                    this.removeFromFavorites(blogId);
                }
            }

            // 处理搜索
            async handleSearch() {
                const query = $('.search-input').val().trim();
                if (query) {
                    try {
                        const response = await fetch(`/api/blog/posts/search?q=${encodeURIComponent(query)}`);
                        const result = await response.json();
                        
                        if (result.success) {
                            this.blogData = result.data;
                            this.renderBlogList();
                        } else {
                            this.searchBlogs(query);
                        }
                    } catch (error) {
                        console.error('搜索失败:', error);
                        this.searchBlogs(query);
                    }
                }
            }

            // 本地搜索（fallback）
            searchBlogs(query) {
                const filteredBlogs = this.blogData.filter(blog => 
                    blog.title.toLowerCase().includes(query.toLowerCase()) ||
                    blog.content.toLowerCase().includes(query.toLowerCase())
                );
                
                const blogList = $('#blogList');
                blogList.empty();
                
                if (filteredBlogs.length === 0) {
                    blogList.html('<div class="no-results">没有找到相关文章</div>');
                } else {
                    filteredBlogs.forEach(blog => {
                        const blogItem = this.createBlogItem(blog);
                        blogList.append(blogItem);
                    });
                }
            }

            // 按类型加载热门文章
            async loadPopularArticlesByType(type) {
                try {
                    let sortedArticles = [...this.popularArticles];
                    
                    switch(type) {
                        case 'views':
                            sortedArticles.sort((a, b) => b.views - a.views);
                            break;
                        case 'likes':
                            sortedArticles.sort((a, b) => b.likes - a.likes);
                            break;
                        case 'comments':
                            sortedArticles.sort((a, b) => b.comments - a.comments);
                            break;
                    }
                    
                    this.popularArticles = sortedArticles.slice(0, 5);
                    this.renderPopularArticles();
                } catch (error) {
                    console.error('加载热门文章失败:', error);
                }
            }

            // 更新文章点赞数（API调用）
            async updateArticleLikes(articleId, newLikes) {
                // 这里可以调用管理端API来更新点赞数
                // 由于管理端API需要认证，这里暂时只做本地更新
                console.log(`更新文章 ${articleId} 的点赞数为: ${newLikes}`);
            }

            // 保存到收藏夹
            saveToFavorites(blogId) {
                const userEmail = localStorage.getItem('userEmail');
                let favorites = JSON.parse(localStorage.getItem(`favorites_${userEmail}`) || '[]');
                
                if (!favorites.includes(blogId)) {
                    favorites.push(blogId);
                    localStorage.setItem(`favorites_${userEmail}`, JSON.stringify(favorites));
                }
            }

            // 从收藏夹移除
            removeFromFavorites(blogId) {
                const userEmail = localStorage.getItem('userEmail');
                let favorites = JSON.parse(localStorage.getItem(`favorites_${userEmail}`) || '[]');
                
                favorites = favorites.filter(id => id !== blogId);
                localStorage.setItem(`favorites_${userEmail}`, JSON.stringify(favorites));
            }

            // HTML转义
            escapeHtml(text) {
                const div = document.createElement('div');
                div.textContent = text;
                return div.innerHTML;
            }
        }

        // 创建博客管理器实例
        const blogManager = new BlogManager();

        // 初始化博客页面
        $(document).ready(function() {
            // 检查登录状态
            checkLoginStatus();
            
            // 初始化博客管理器
            blogManager.init();
        });

        // 查看博客详情
        function viewBlogDetail(blogId) {
            window.location.href = `/blog/${blogId}`;
        }

        // 订阅功能
        $('.subscribe-btn').on('click', function() {
            const userEmail = localStorage.getItem('userEmail');
            
            if (!userEmail) {
                alert('请先登录后再订阅');
                return;
            }
            
            const category = $(this).data('category');
            if ($(this).hasClass('subscribed')) {
                $(this).removeClass('subscribed');
                $(this).text('订阅');
                // 取消订阅
                unsubscribeCategory(category);
            } else {
                $(this).addClass('subscribed');
                $(this).text('已订阅');
                // 订阅
                subscribeCategory(category);
            }
        });

        // 订阅分类
        function subscribeCategory(category) {
            const userEmail = localStorage.getItem('userEmail');
            let subscriptions = JSON.parse(localStorage.getItem(`subscriptions_${userEmail}`) || '[]');
            
            if (!subscriptions.includes(category)) {
                subscriptions.push(category);
                localStorage.setItem(`subscriptions_${userEmail}`, JSON.stringify(subscriptions));
            }
        }

        // 取消订阅
        function unsubscribeCategory(category) {
            const userEmail = localStorage.getItem('userEmail');
            let subscriptions = JSON.parse(localStorage.getItem(`subscriptions_${userEmail}`) || '[]');
            
            subscriptions = subscriptions.filter(cat => cat !== category);
            localStorage.setItem(`subscriptions_${userEmail}`, JSON.stringify(subscriptions));
        }

        // 检查登录状态
        function checkLoginStatus() {
            const userEmail = localStorage.getItem('userEmail');
            const userName = localStorage.getItem('userName') || (userEmail ? userEmail.split('@')[0] : '用户');
            
            const authButtons = document.getElementById('authButtons');
            const userInfo = document.getElementById('userInfo');
            const userNameElement = document.getElementById('userName');
            
            if (userEmail && authButtons && userInfo && userNameElement) {
                authButtons.style.display = 'none';
                userInfo.style.display = 'flex';
                userNameElement.textContent = userName;
            } else if (authButtons && userInfo) {
                authButtons.style.display = 'flex';
                userInfo.style.display = 'none';
            }
        }

        // 退出登录
        function logout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.removeItem('userEmail');
                localStorage.removeItem('userName');
                localStorage.removeItem('rememberMe');
                window.location.reload();
            }
        }
    </script>
    
    <!-- 语言切换组件 -->
    <script src="/static/js/language-switcher.js"></script>
</body>
</html>